package com.example.itcacp.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@TableName("me_message")
@JsonIgnoreProperties(ignoreUnknown = true) // 忽略未知字段
public class Message {
    @TableId(type = IdType.AUTO)  //表示这个字段对应数据库表的主键。相同时mp自动关联
    @JsonSerialize(using = ToStringSerializer.class)
    private Long messageId;
    @JsonSerialize(using = ToStringSerializer.class)
    private Long senderId;  // 发送者id
    @JsonSerialize(using = ToStringSerializer.class)
    private Long receiverId;  // 接收者id
    @Enumerated(EnumType.STRING)  // 显式指定使用字符串映射
    private MessageType messageType;
    private Long targetId;
    private Like.ContentType targetType;
    private String title;
    private String content;
    private String status;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;
    public enum MessageType {
        SYSTEM,CONTENT,PRIVATE
    }

    @TableField(exist = false)
    private User sender;  // 新增字段，用于获取发送者信息

    @TableField(exist = false)
    private User receiver;  // 新增字段，用于获取发送者信息

    @TableField(exist = false)
    private Content targetContent; // 目标内容
}
